class Solution:
    def maxJumps(self, arr: list, d: int) -> int:
        def func(pos, memo):
            if memo[pos]:
                return memo[pos]
            res = 0
            for i in range(1, d + 1):
                if i + pos >= len(arr):
                    break
                if arr[pos + i] >= arr[pos]:
                    break
                res = max(res, func(pos + i, memo) + 1)

            for i in range(1, d + 1):
                if pos - i < 0:
                    break
                if arr[pos - i] >= arr[pos]:
                    break
                res = max(res, func(pos - i, memo) + 1)

            memo[pos] = res
            return res

        memo = [0 for _ in range(len(arr))]
        ans = 0
        for pos in range(len(arr)):
            ans = max(ans, func(pos, memo) + 1)

        return ans
